package com.yun.algorithmproblem.leetcode;

import java.util.HashMap;

public class Leetcode2588 {

    public static void main(String[] args) {
        Leetcode2588 obj = new Leetcode2588();
        System.out.println(obj.beautifulSubarrays(new int[]{4, 3, 1, 2, 4}));
    }

    public long beautifulSubarrays(int[] nums) {
        HashMap<Integer, Integer> map = new HashMap<>();
        long ans= 0;
        int prefixOr = 0;
        map.put(0, 1);
        for (int num : nums) {
            prefixOr ^= num;
            ans += map.getOrDefault(prefixOr, 0);
            map.merge(prefixOr,1,Integer::sum);
        }
        return ans;
    }
}
